package cn.iocoder.yudao.module.wms.dal.mysql.inventory;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.wms.controller.admin.inventory.vo.InventoryPageReqVO;
import cn.iocoder.yudao.module.wms.dal.dataobject.inventory.InventoryDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 存货档案 Mapper
 *
 * @author 曾劲松
 */
@Mapper
public interface InventoryMapper extends BaseMapperX<InventoryDO> {

    default PageResult<InventoryDO> selectPage(InventoryPageReqVO reqVO, Collection<Long> classifyIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InventoryDO>()
                .likeIfPresent(InventoryDO::getCode, reqVO.getCode())
                .likeIfPresent(InventoryDO::getName, reqVO.getName())
                .likeIfPresent(InventoryDO::getSpecModel, reqVO.getSpecModel())
                .inIfPresent(InventoryDO::getClassifyId, classifyIds)
                .eqIfPresent(InventoryDO::getIsBatch, reqVO.getIsBatch())
                .likeIfPresent(InventoryDO::getBrand, reqVO.getBrand())
                .betweenIfPresent(InventoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InventoryDO::getCode));
    }

    default List<InventoryDO> selectList(String query) {
        return selectList(new LambdaQueryWrapperX<InventoryDO>()
                .like(InventoryDO::getCode,query)
                .or()
                .like(InventoryDO::getName,query)
                .or()
                .like(InventoryDO::getSpecModel,query)
                .orderByDesc(InventoryDO::getCode)
                .last("limit 100"));
    }

}